package com.iwuke.dance.wallet.settings;

import android.view.View;
import android.widget.TextView;

import com.iwuke.dance.R;
import com.iwuke.dance.activity.BaseActivity;
import com.iwuke.dance.gadget_view.TitleBarView;
import com.iwuke.dance.http_request.Bean;
import com.iwuke.dance.http_request.PathUrl;
import com.iwuke.dance.util.SharedPreferencesUtil;
import com.iwuke.dance.util.ToastUtil;
import com.iwuke.dance.util.Util;
import com.iwuke.dance.util.independent_edit_text.IndependentEditTextUtil;
import com.iwuke.dance.util.merchants_connect.NetworkEvent;

import java.util.HashMap;
import java.util.Map;

import de.greenrobot.event.Subscribe;
import de.greenrobot.event.ThreadMode;

/**
 * @author: 魏从响
 * @date: 2025/10/9
 * 验证支付密码
 */
public class VerifyPaymentPasswordActivity extends BaseActivity implements View.OnClickListener {

    private TitleBarView title_bar;
    private TextView tv_verification_method;
    private IndependentEditTextUtil independentEditTextUtil;

    /**
     * @description 网络实时监听
     */
    @Subscribe(threadMode = ThreadMode.MainThread)
    public void onEvent(NetworkEvent networkEvent){
        BaseActivity.setConnect(VerifyPaymentPasswordActivity.this,networkEvent,title_bar);
    }

    @Override
    protected int getView() {
        return R.layout.activity_verify_payment_password;
    }

    @Override
    protected void init(View mView) {
        title_bar = findViewById(R.id.title_bar);
        //验证方式
        tv_verification_method = findViewById(R.id.tv_verification_method);

        independentEditTextUtil = new IndependentEditTextUtil(this, mView);


        title_bar.setTitleText("修改支付密码");
        title_bar.setLeftOnClick(this);
        //验证方式
        tv_verification_method.setOnClickListener(this);
    }

    @Override
    protected void initData() {
        independentEditTextUtil.setOnEditTextClick(new IndependentEditTextUtil.OnEditTextClick() {
            @Override
            public void onEditTextClick(String value) {
                //跳转设置新6位数密码页面
                requestData(value);
            }

            @Override
            public void onResendTimeClick() {
               //发送验证码请求

            }
        });
    }

    /**
     * @description 请求数据
     * @param
     * @return
     * @author 魏从响
     * @time 2025/10/10 10:39
     */
    private void requestData(String value) {
        Map<String, Object> map = new HashMap<>();
        map.put("walletId", SharedPreferencesUtil.getInstance().getWalletId());
        map.put("password",value);
        PathUrl.verifyPassword(map, new PathUrl.DataCallBack<Bean>() {
            @Override
            public void onSucess(Bean bean) {
                Util.setIntent(VerifyPaymentPasswordActivity.this, ChangePaymentPasswordActivity.class);
                finish();
            }

            @Override
            public void onFail(String errorCode) {
                ToastUtil.setToast(VerifyPaymentPasswordActivity.this,errorCode);
            }
        });
    }


    @Override
    public void onClick(View v) {
        if (v.getId()==R.id.img_left){
            finish();
        }else if (v.getId()==R.id.tv_verification_method){//验证方式
            Util.setIntent(VerifyPaymentPasswordActivity.this, PaymentPasswordActivity.class);
            finish();
        }
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (independentEditTextUtil!=null){
            independentEditTextUtil.onDestroy();
        }
        if (independentEditTextUtil!=null){
            independentEditTextUtil=null;
        }
    }

}
